import { QueryPageDto } from '@/common/dto/queryPage';
import { StatusValue, Office, UserType } from '@/enum/common.enum';
import { ApiProperty, IntersectionType, OmitType, PartialType, PickType } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import {
  IsBoolean,
  IsEmail,
  // IsIdentityCard, // 没有中国...
  IsMobilePhone,
  IsNotEmpty,
  IsOptional,
  IsString,
  MaxLength,
  MinLength,
} from 'class-validator';
import { $enum } from 'ts-enum-util';

export class UserDto {
  @ApiProperty({ description: '账号' })
  @IsString({ message: 'username类型出错' })
  @IsNotEmpty({ message: '账号不能为空' })
  @MinLength(5, { message: '账号至少5个字符' })
  @MaxLength(20, { message: '账号最多20个字符' })
  readonly username: string;

  @ApiProperty({ description: '密码' })
  @IsString({ message: 'password类型出错' })
  @IsNotEmpty({ message: '密码不能为空' })
  @Exclude({ toPlainOnly: true })
  password: string;

  @ApiProperty({ description: '用户账号' })
  @IsString({ message: 'account 类型错误，正确类型 string' })
  @IsNotEmpty({ message: 'account 不能为空' })
  @MinLength(5, { message: '账号至少5个字符' })
  @MaxLength(20, { message: '账号最多20个字符' })
  readonly account: string;

  @ApiProperty({ description: '手机号', required: false })
  @IsString({ message: 'phoneNum 类型错误，正确类型 string' })
  @IsMobilePhone('zh-CN', { strictMode: false }, { message: '请输入正确的手机号' })
  @IsOptional()
  readonly phoneNum?: string;

  @ApiProperty({ description: '邮箱', required: false })
  @IsString({ message: 'email 类型错误，正确类型 string' })
  @IsEmail()
  @IsOptional()
  readonly email?: string;

  @ApiProperty({ description: '确认密码' })
  @IsString({ message: ' confirmPassword 类型错误，正确类型 string' })
  @Exclude({ toPlainOnly: true })
  confirmPassword: string;

  @ApiProperty({
    type: String,
    description: '员工状态 0:禁用 1:启用',
    enum: $enum(StatusValue).getValues(),
  })
  @IsBoolean({ message: '状态 1-有效 0-无效' })
  readonly status: StatusValue;
  @ApiProperty({
    type: String,
    description: '员工类型 1:超级管理员 2:普通用户',
    enum: $enum(UserType).getValues(),
  })
  readonly type: UserType;

  @ApiProperty({
    description: `  // 总经理
  CEO = 0,
  // 副总
  MANAGER = 1,
  // 讲师
  TEACHER = 2,
  // 辅导员
  COUNSELOR = 3,
  // 市场部
  MARKETER = 4,
  // 财务部
  FINANCIAL = 5,
  // 人事部
  HR = 6,`,
    type: String,
    enum: $enum(Office).getValues(),
  })
  @IsString({ message: ' office类型错误, 正确类型 string' })
  readonly office?: Office;

  @ApiProperty({ description: '简介' })
  @IsString({ message: ' summary类型错误, 正确类型 string' })
  readonly summary?: string;

  @ApiProperty({ description: '身份证' })
  // @IsIdentityCard()
  @IsString({ message: 'idCard类型错误, 正确类型 string' })
  readonly idCard: string;

  @ApiProperty({ description: '照片', required: false })
  @IsString({ message: 'photo 类型错误，正确类型 string' })
  @IsOptional()
  readonly photo?: string;

  @ApiProperty({ description: '头像', required: false })
  @IsString({ message: 'avatar 类型错误，正确类型 string' })
  @IsOptional()
  avatar?: string;
}
export class LoginUserDto extends PickType(UserDto, ['username', 'password']) {}
// 排除属性 合并属性组合

/**
 * 合并属性组合
 * IntersectionType 合并组合
 * PartialType 设置成可选属性
 * OmitType 排除属性
 */
export class UserListDto extends IntersectionType(
  PartialType(
    OmitType(UserDto, ['password', 'confirmPassword', 'avatar', 'photo', 'account', 'summary'])
  ),
  PartialType(QueryPageDto)
  // OmitType(UserDto, ['password', 'confirmPassword', 'avatar', 'photo'])
  //
) {}
// export class UserListDto extends OmitType(UserDto, ['password', 'confirmPassword', 'avatar', 'photo']);
// export class UserListDto extends PickType(UserDto, ['username', 'password', 'account', 'phoneNum', 'email', 'status', 'type', 'office', 'summary', 'idCard', 'photo', 'avatar']);
// OmitType 用来排除某个类型的属性
// IntersectionType 合并多个类的属性
// PartialType 用来指定某个类型的属性
// export class LoginUserDto extends PartialType(UserDto) {}
